import type { SuanzhuGatewayResponse } from '../types'
import {
  StatusEnum,
  AppTypeEnum,
  ConnectModeEnum,
  ProviderTypeEnum
} from '../types'

/**
 * 算珠网关模拟数据
 */
export const createMockData = (qrcode: string): SuanzhuGatewayResponse => {
  return {
    qrcodeInfo: {
      qrcodeId: qrcode,
      merchantId: 'MCH_SZ_001',
      storeId: 'STORE_001',
      appId: 'APP_SZ_001',
      batchId: 'BATCH_001',
      status: StatusEnum.ENABLED,
      qrCodeUrl: `https://suanzhu.gateway.com/pay?qrcode=${qrcode}`,
      remark: '算珠网关测试二维码',
      extrainfo: '{"gateway":"suanzhu","version":"1.0"}',
      createdTime: '2024-01-01 10:00:00',
      updatedTime: '2024-01-15 14:30:00'
    },
    appInfo: {
      appId: 'APP_SZ_001',
      appName: '算珠网关支付应用',
      appType: AppTypeEnum.WEB,
      connectMode: ConnectModeEnum.DIRECT,
      merchantId: 'MCH_SZ_001',
      notifyUrl: 'https://suanzhu.gateway.com/notify',
      returnUrl: 'https://suanzhu.gateway.com/return',
      status: StatusEnum.ENABLED,
      createdTime: '2024-01-01 10:00:00',
      updatedTime: '2024-01-10 16:20:00'
    },
    merchantInfo: {
      merchantId: 'MCH_SZ_001',
      merchantName: '算珠测试商户',
      providerId: 'SP_SZ_001',
      agentId: 'AGENT_001',
      contactName: '张三',
      contactTelephone: '021-12345678',
      remark: '算珠测试商户备注',
      status: StatusEnum.ENABLED,
      createdTime: '2024-01-01 10:00:00',
      updatedTime: '2024-01-08 11:45:00'
    },
    serviceProviderInfo: {
      providerId: 'SP_SZ_001',
      providerName: '算珠支付服务商',
      providerType: ProviderTypeEnum.PLATFORM,
      contactPerson: '李四',
      contactPhone: '021-87654321',
      contactEmail: 'service@suanzhu.com',
      merchantCount: 100,
      status: StatusEnum.ENABLED,
      createdTime: '2024-01-01 10:00:00',
      updatedTime: '2024-01-05 09:15:00'
    }
  }
}

/**
 * 模拟网络延迟
 */
export const mockDelay = (ms: number = 1000): Promise<void> => {
  return new Promise(resolve => setTimeout(resolve, ms))
}

/**
 * 模拟错误场景
 */
export const createMockError = (qrcode: string): SuanzhuGatewayResponse => {
  const errorMessages = [
    '二维码已过期',
    '商户信息不存在',
    '应用配置异常',
    '服务商状态异常'
  ]

  return {
    error: errorMessages[Math.floor(Math.random() * errorMessages.length)]
  }
}